package com.qumitech.visualnovel.component.aop;

import com.qumitech.visualnovel.component.util.GetPropertiesUtils;
import com.qumitech.visualnovel.component.config.Config;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author fangzhipeng
 *
 *
 */
@Component
@Aspect
public class BizQuartzAop {

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());
    private final String quartz = Config.getProperty("app.quartz.isOpen");

    //为定时任务增加耗时统计
    @Pointcut("execution(* com.qumitech.visualnovel.component.quartz.BizQuartz.*(..))")
    public void aopMethod(){}

    @Around("aopMethod()")
    public Object  around(ProceedingJoinPoint joinPoint) throws Throwable{
        Boolean startQuartz = false;
        if (quartz != null){
            startQuartz = Boolean.parseBoolean(quartz);
        }
        if (!startQuartz) {
            //LOG.info("localenv won't start quartz, method name <{}>", joinPoint.getSignature().getName());
            return null;
        }
        long time = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        //LOG.info("excuate cron, method name <{}> cost <{}>", joinPoint.getSignature().getName(),  (System.currentTimeMillis() - time));
        return proceed;
    }

    private boolean isNeedLoginMethod(ProceedingJoinPoint joinPoint) {
        return false;
    }
}
